﻿<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php
	require"connectdb.php";
	$username = isset($_POST['username'])?$_POST['username']:"";
   	$pwd = isset($_POST['password'])?$_POST['password']:"";
	$result=mysql_query("SELECT * from reagent_users WHERE username='".$username."'");
	if(!$result) $true_username="";
	else $true_username=$username;
	$row=mysql_fetch_array($result);
	$true_pwd=$row['password'];

	if($username!=""){
		if($true_username!=""){
        	 if($pwd == $true_pwd){
				 	$_SESSION['loggedin']=1;
				 	$_SESSION['user']=$username;
            	   echo("<meta http-equiv=\"refresh\" content=\"0.1;url=data.php\">");
				   $success=1;
			 }
      	   	 else{
        	     $success=2; 
        	 }
     	}
	 	else $success=3;
	}
?>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>聚合物产品工程科技创新团队药品管理软件|登录</title>
<link rel="stylesheet" type="text/css" href="reagentdb.css" />

</head>

<body>
<script type="text/javascript">

function validate_required(field,alerttxt)
{
with (field)
  {
  if (value==null||value=="")
    {alert(alerttxt);return false}
  else {return true}
  }
}

function validate_form(thisform)
{
with (thisform)
  {
  	if (validate_required(username,"请输入用户名")==false)
    	{username.focus();return false}
  	if (validate_required(password,"请输入密码")==false)
    	{password.focus();return false}
 }
}
</script>

<div class="container">
  <div class="header">
  	<img src="ypglhead.png" width="800" height="120" alt="标题" />
  </div>
  <div class="content">
    <h2>请登录</h2>
    <form action="login.php" onsubmit="return validate_form(this)" method="post">
	  <p>用户名: <input type="text" name="username" size="20"></p>
	  <p>&nbsp;&nbsp;&nbsp;&nbsp;密码: 
      <input type="password" name="password" size="20"></p>
		<input type="submit" value="登录"> 
	</form>
    
    <?php
	switch ($success)
		{
		case 1:
  			echo "登录成功";
  			break;
		case 2:
 			echo "密码错误";
  			break;
		case 3:
  			echo "用户名错误";
 			 break;
		default:
}
?>
    <!-- end .content --></div>
  <!-- end .container --></div>
</body>
</html>